package com.ruoyi.ams.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;

import com.ruoyi.common.core.domain.model.AmsAssetType;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class TreeListType implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Long assetTypeId;
    private Long parentId;
    private String ancestors;
    private String assetTypeName;
    private String assetTypeCode;

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeListType> children;

    public TreeListType(AmsAssetType type) {
        this.id = type.getAssetTypeId();
        this.assetTypeId = type.getAssetTypeId();
        this.parentId = type.getParentId();
        this.ancestors = type.getAncestors();
        this.assetTypeName = type.getAssetTypeName();
        this.assetTypeCode = type.getAssetTypeCode();
        if (type.getChildren() != null) {
            this.children = type.getChildren().stream().map(TreeListType::new).collect(Collectors.toList());
        }
    }
}
